﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace WinApp.Until
{
    public static class ConfigHelper
    {
        public static IConfigurationRoot? _configuration;

        static ConfigHelper()
        {
            if (_configuration == null)
            {
                _configuration = new ConfigurationBuilder()
                    .AddInMemoryCollection() //将配置文件的数据加载到内存中
                    .SetBasePath(Directory.GetCurrentDirectory()) //指定配置文件所在的目录
                    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) //指定加载的配置文件  --划重点..记得始终复制
                    .Build(); //编译成对象
            }
        }

        public static string GetValue(string key)
        {
            var value = _configuration?[key];
            if (value == null)
            {
                return "";
            }

            return value;
        }

        public static string GetHost()
        {
            //todo 激活码(后续如果别的客户也用需要加)
            var hostIp = _configuration?["WebHost"];
            if (hostIp == null)
            {
                return "";
            }

            return hostIp;
        }

        public static string GetTenancy()
        {
            //todo 激活码(后续如果别的客户也用需要加)
            var tenancy = _configuration?["Tenancy"];
            if (tenancy == null)
            {
                return "";
            }

            return tenancy;
        }

    }
}
